package io.github.harmonly.skyblock.util;

import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.scheduler.BukkitWorker;

import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.function.Consumer;

public class Scheduler {

    private static Plugin plugin;
    private static BukkitScheduler scheduler;

    public static void enable(Plugin plugin) {
        Scheduler.plugin = plugin;
        Scheduler.scheduler = plugin.getServer().getScheduler();
    }

    public static int scheduleSyncDelayedTask(Runnable task, long delay) {
        return scheduler.scheduleSyncDelayedTask(plugin, task, delay);
    }

    public static int scheduleSyncDelayedTask(Runnable task) {
        return scheduler.scheduleSyncDelayedTask(plugin, task);
    }

    public static int scheduleSyncRepeatingTask(Runnable task, long delay, long period) {
        return scheduler.scheduleSyncRepeatingTask(plugin, task, delay, period);
    }

    public static <T> Future<T> callSyncMethod(Callable<T> task) {
        return scheduler.callSyncMethod(plugin, task);
    }

    public static void cancelTask(int taskId) {
        scheduler.cancelTask(taskId);
    }

    public static void cancelTasks(Plugin plugin) {
        scheduler.cancelTasks(plugin);
    }

    public static boolean isCurrentlyRunning(int taskId) {
        return scheduler.isCurrentlyRunning(taskId);
    }

    public static boolean isQueued(int taskId) {
        return scheduler.isQueued(taskId);
    }

    public static List<BukkitWorker> getActiveWorkers() {
        return scheduler.getActiveWorkers();
    }

    public static List<BukkitTask> getPendingTasks() {
        return scheduler.getPendingTasks();
    }

    public static BukkitTask runTask(Runnable task) throws IllegalArgumentException {
        return scheduler.runTask(plugin, task);
    }

    public static void runTask(Consumer<? super BukkitTask> task) throws IllegalArgumentException {
        scheduler.runTask(plugin, task);
    }

    public static BukkitTask runTaskAsynchronously(Runnable task) throws IllegalArgumentException {
        return scheduler.runTaskAsynchronously(plugin, task);
    }

    public static void runTaskAsynchronously(Consumer<? super BukkitTask> task) throws IllegalArgumentException {
        scheduler.runTaskAsynchronously(plugin, task);
    }

    public static BukkitTask runTaskLater(Runnable task, long delay) throws IllegalArgumentException {
        return scheduler.runTaskLater(plugin, task, delay);
    }

    public static void runTaskLater(Consumer<? super BukkitTask> task, long delay) throws IllegalArgumentException {
        scheduler.runTaskLater(plugin, task, delay);
    }

    public static BukkitTask runTaskLaterAsynchronously(Runnable task, long delay) throws IllegalArgumentException {
        return scheduler.runTaskLaterAsynchronously(plugin, task, delay);
    }

    public static void runTaskLaterAsynchronously(Consumer<? super BukkitTask> task, long delay) throws IllegalArgumentException {
        scheduler.runTaskLaterAsynchronously(plugin, task, delay);
    }

    public static BukkitTask runTaskTimer(Runnable task, long delay, long period) throws IllegalArgumentException {
        return scheduler.runTaskTimer(plugin, task, delay, period);
    }

    public static void runTaskTimer(Consumer<? super BukkitTask> task, long delay, long period) throws IllegalArgumentException {
        scheduler.runTaskTimer(plugin, task, delay, period);
    }

    public static BukkitTask runTaskTimerAsynchronously(Runnable task, long delay, long period) throws IllegalArgumentException {
        return scheduler.runTaskTimerAsynchronously(plugin, task, delay, period);
    }

    public static void runTaskTimerAsynchronously(Consumer<? super BukkitTask> task, long delay, long period) throws IllegalArgumentException {
        scheduler.runTaskTimerAsynchronously(plugin, task, delay, period);
    }
}
